#include <stdio.h>
#include <string.h>
#include <errno.h>

void pr_stdio(char* stream, FILE* fp) {
	printf("stream = %s\n", stream);

	if (fp->_IO_file_flags & _IO_UNBUFFERED)
		printf("unbuffered");
	else if (fp->_IO_file_flags & _IO_LINE_BUF)
		printf("linebuffer");
	else
		printf("full buffer");

	printf(", buffer size = %d\n", fp->_IO_buf_end-fp->_IO_buf_base);
}

int main() {
	FILE* fp;
	fputs("enter any character\n", stdout);
	if (getchar() == EOF) {
		printf("getchar error: %s\n", strerror(errno));
		return -1;
	}
	fputs("one line to standard error\n", stderr);

	pr_stdio("stdin", stdin);
	pr_stdio("stdout", stdout);
	pr_stdio("stderr", stderr);

	if ((fp=fopen("/etc/motd", "r")) == NULL) {
		printf("fopen error: %s\n", strerror(errno));
		return -1;
	}
	if (getc(fp) == EOF) {		
		printf("getc error: %s\n", strerror(errno));
		return -1;
	}
	pr_stdio("/etc/motd", fp);
	return 0;
}